package com.mf.ergate.controller.monitor;

import com.mf.ergate.api.monitor.LoginLogRemoteService;
import com.mf.ergate.api.monitor.model.dto.LoginLogCreateDto;
import com.mf.ergate.api.monitor.model.dto.LoginLogDeleteDto;
import com.mf.ergate.api.monitor.model.dto.LoginLogQueryDto;
import com.mf.ergate.api.monitor.model.dto.LoginLogUpdateDto;
import com.mf.ergate.api.monitor.model.vo.LoginLogVo;
import com.mf.ergate.common.utils.MfBeanUtils;
import com.mf.ergate.domain.model.monitor.LoginLogEntity;
import com.mf.ergate.service.monitor.LoginLogService;
import com.mf.framework.common.model.Page;
import com.mf.framework.common.model.RemotePage;
import com.mf.framework.common.model.Result;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 登录日志Controller
 * User: zhaoming
 * DateTime: 2019-02-12
 * To change this template use File | Settings | File Templates.
 */
@Api(value = "/api/loginLog", tags = "LoginLogController", description = "登录日志服务")
@RestController
public class LoginLogController implements LoginLogRemoteService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private LoginLogService loginLogService;

    /**
     * 新增
     * @param loginLogCreateDto 登录日志新增Dto
     * @return 登录日志
     */
    public Result<LoginLogVo> insert(@RequestBody LoginLogCreateDto loginLogCreateDto) {
        LoginLogEntity loginLogEntity = MfBeanUtils.copyObject(loginLogCreateDto, LoginLogEntity.class);
        loginLogEntity = loginLogService.insert(loginLogEntity);
        LoginLogVo loginLogVo = MfBeanUtils.copyObject(loginLogEntity, LoginLogVo.class);
        return new Result<>(loginLogVo);
    }

    /**
     * 根据唯一编号更新
     * @param loginLogUpdateDto 登录日志更新Dto
     * @return 执行结果
     */
    public Result<Boolean> updateByUniqueNo(@RequestBody LoginLogUpdateDto loginLogUpdateDto) {
        LoginLogEntity loginLogEntity = MfBeanUtils.copyObject(loginLogUpdateDto, LoginLogEntity.class);
        Boolean flag = loginLogService.updateByUniqueNo(loginLogEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号删除(逻辑删除)
     * @param loginLogDeleteDto 登录日志删除Dto
     * @return 结果集
     */
    public Result<Boolean> deleteByUniqueNo(@RequestBody LoginLogDeleteDto loginLogDeleteDto){
        LoginLogEntity loginLogEntity = MfBeanUtils.copyObject(loginLogDeleteDto, LoginLogEntity.class);
        Boolean flag = loginLogService.deleteByUniqueNo(loginLogEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号查询
     * @param uniqueNo 唯一编号
     * @return 登录日志
     */
    public Result<LoginLogVo> selectByUniqueNo(@RequestBody String uniqueNo) {
        LoginLogEntity loginLogEntity = loginLogService.selectByUniqueNo(uniqueNo);
        LoginLogVo loginLogVo = MfBeanUtils.copyObject(loginLogEntity, LoginLogVo.class);
        return new Result<>(loginLogVo);
    }

    /**
     * 根据条件查询
     * @param loginLogQueryDto 登录日志查询Dto
     * @return 登录日志列表
     */
    public Result<List<LoginLogVo>> selectByCondition(@RequestBody LoginLogQueryDto loginLogQueryDto) {
        List<LoginLogEntity> loginLogEntities = loginLogService.selectByCondition(loginLogQueryDto);
        List<LoginLogVo> loginLogVos = MfBeanUtils.copyList(loginLogEntities, LoginLogVo.class);
        return new Result<>(loginLogVos);
    }

    /**
     * 根据条件查询数量
     * @param loginLogQueryDto 登录日志查询Dto
     * @return 数量
     */
    public Result<Integer> selectCount(@RequestBody LoginLogQueryDto loginLogQueryDto) {
        return new Result<>(loginLogService.selectCount(loginLogQueryDto));
    }

    /**
     * 根据条件分页查询
     * @param remotePage 远程分页对象
     * @return 登录日志分页列表
     */
    public Result<Page<LoginLogVo>> selectPage(@RequestBody RemotePage<LoginLogQueryDto> remotePage){
        Page<LoginLogEntity> loginLogEntityPage = loginLogService.selectPage(remotePage.getPage(), remotePage.getObj());
        Page<LoginLogVo> page = MfBeanUtils.copyPage(loginLogEntityPage, LoginLogVo.class);
        return new Result<>(page);
    }

}